
import 'package:flutter/material.dart';

/// 主题配置
class ThemeConfig {
  static ThemeData configTheme(MaterialColor primaryColor, MaterialColor accentColor){

    var themeData = ThemeData(
      primarySwatch:primaryColor,
      accentColor: accentColor,
    );

    themeData = themeData.copyWith(
      primaryColor: primaryColor,
      hintColor: themeData.hintColor.withAlpha(90),
      errorColor: Colors.red,
      cursorColor: accentColor,
      textTheme: themeData.textTheme.copyWith(
        /// 解决中文hint不居中的问题 https://github.com/flutter/flutter/issues/40248
          subhead: themeData.textTheme.subhead
              .copyWith(textBaseline: TextBaseline.alphabetic)),
      textSelectionColor: accentColor.withAlpha(60),
      textSelectionHandleColor: accentColor.withAlpha(60),
      toggleableActiveColor: accentColor,
      chipTheme: themeData.chipTheme.copyWith(
        pressElevation: 0,
        padding: EdgeInsets.symmetric(horizontal: 10),
        labelStyle: themeData.textTheme.caption,
        backgroundColor: themeData.chipTheme.backgroundColor.withOpacity(0.1),
      ),
      inputDecorationTheme:_configInputDecorationTheme(themeData),
    );

    return themeData;
  }

  //配置全局的输入框的装饰器
  static _configInputDecorationTheme(ThemeData theme){

    var primaryColor = theme.primaryColor;
    var dividerColor = theme.dividerColor;
    var errorColor = theme.errorColor;
    var disabledColor = theme.disabledColor;

    var width = 0.5;

    return InputDecorationTheme(
      hintStyle: TextStyle(fontSize: 14),

      errorBorder: UnderlineInputBorder(
          borderSide: BorderSide(width: width, color: errorColor)),

      focusedErrorBorder: UnderlineInputBorder(
          borderSide: BorderSide(width: 0.7, color: errorColor)),

      focusedBorder: UnderlineInputBorder(
          borderSide: BorderSide(width: width, color: primaryColor)),

      enabledBorder: UnderlineInputBorder(
          borderSide: BorderSide(width: width, color: dividerColor)),

      border: UnderlineInputBorder(
          borderSide: BorderSide(width: width, color: dividerColor)),

      disabledBorder: UnderlineInputBorder(
          borderSide: BorderSide(width: width, color: disabledColor)),

    );

  }
}